﻿using System;
using System.Collections.Generic;
using System.Web;
using ZLDC.Common.Estate;
using ZLDC.Topo.BLL.Estate;
using System.Data;

namespace ZLDC.Estate
{
    public class CHandlerCustomer
    {
        public static void ChooseMethod()
        {

            string act = _Request.GetString("act", "");
            switch (act)
            {
                case "CustomerSave":
                    CustomerSave();
                    break;
                case "p_CustomerList":
                    p_CustomerList();
                    break;
                case "customer_list":
                    CustomerList();
                    break;
                case "customer_list_action":
                    CustomerListAction();
                    break;
                case "customer_detail":
                    CustomerDetail();
                    break;
                case "customer_del":
                    CustomerDel();
                    break;
                case "customer_change":
                    CustomerChange();
                    break;
                case "customer_changeself":
                    CustomerChangeSelf();
                    break;
                case "CustomerFollow_Save":
                    CustomerFollowSave();
                    break;
                case "CustomerFollowSave1":
                    CustomerFollowSave1();
                    break;
                case "CustomerAlertSave":
                    CustomerAlertSave();
                    break;
                case "SelectCustomerFollow":
                    SelectCustomerFollow();
                    break;
                case "SelectCustomerAlert":
                    SelectCustomerAlert();
                    break;
                case "p_CustomerAlert_Update":
                    p_CustomerAlert_Update();
                    break;
                case "p_CustomerReportList":
                    p_CustomerReportList();
                    break;
                case "p_CustomerAlertReportList":
                    p_CustomerAlertReportList();
                    break;
                case "SelectCustomerOrFollowList":
                    SelectCustomerOrFollowList();
                    break;
                case "UpdateStatus":
                    UpdateStatus();
                    break;
                case "DeleteCustomerAlert":
                    DeleteCustomerAlert();
                    break;
                case "GetCustTelList":
                    GetCustTelList();
                    break;
                case "p_CustomerRecycleList":
                    p_CustomerRecycleList();
                    break;
                case "DeleteCustomer":
                    DeleteCustomer();
                    break;
                case "DeleteWeekDaysCustomer":
                    DeleteWeekDaysCustomer();
                    break;
                case "UpdateDltFlag":
                    UpdateDltFlag();
                    break;
                case "DeleteCFollow":
                    p_Customerfollow_delete();
                    break;

                #region 转介客

                case "customerchangecheck_list": CustomerChangeCheckList();
                    break;
                case "customerchangecheck_ok": CustomerChangeCheckOK();
                    break;
                case "customerchangecheck_change": CustomerChangeCheckChange();
                    break;
                case "customerchangecheck_delete": CustomerChangeCheckDelete();
                    break;

                case "customerChange_list": CustomerChangeList();
                    break;
                case "customerChange_list_action": CustomerChangeListAction();
                    break;
                case "changeCustomer_list": CustomerChangeLogList();
                    break;
                case "CustomerCheckListAction": CustomerCheckListAction();
                    break;
                case "UpdateCustomerCheckList": UpdateCustomerCheckList();
                    break;
                case "ShowOtherCustomer": ShowOtherCustomer();
                    break;

                #endregion

                #region 客源匹配

                case "customer_match":
                    CustomerMatch();
                    break;

                #endregion

                #region 我的客源

                case "mycustomer":
                    MyCustomer();
                    break;
                case "p_MyCustomerList":
                    p_MyCustomerList();
                    break;

                #endregion

                #region 成交客管理

                case "customer_tranction_edit":
                    CustomerTranctionEdit(); break;

                #endregion

                case "showFloorPaper_save":
                    p_showFloorPaper_save();
                    break;
                case "ShowFloorPaper_list":
                    ShowFloorPaper_list();
                    break;
                case "ShowFloorPaper_delete":
                    ShowFloorPaper_delete();
                    break;
                case "GetUserList":
                    GetUserList();
                    break;
            }
        }

        public static void CustomerSave()
        {
            int Id = _Request.GetIntForm("cid", 0);
            string customer = _Request.GetStringForm("customer", ""); string customerTel = _Request.GetStringForm("customerTel", ""); string customerClass = _Request.GetStringForm("customerClass", ""); if (customerClass == "请选择")
            {
                customerClass = "";
            }
            string occupation = _Request.GetStringForm("occupation", ""); if (occupation == "请选择")
            {
                occupation = "";
            }
            string agent = _Request.GetStringForm("agent", ""); string agentTel = _Request.GetStringForm("agentTel", ""); string infoFrom = _Request.GetStringForm("infoFrom", ""); string buyingMotive = _Request.GetStringForm("buyingMotive", ""); string remark = _Request.GetStringForm("remark", ""); string dId = _Request.GetStringForm("did", ""); if (dId == "")
            {
                dId = "0";
            }
            string dname = _Request.GetStringForm("dname", "");
            if (dname == "")
            {
                dname = "全部";
            }
            string aId = _Request.GetStringForm("areaid", "");
            if (aId == "")
            {
                aId = "0";
            }
            string area = _Request.GetStringForm("areaname", ""); if (area == "")
            {
                area = "全部";
            }
            string estate = _Request.GetStringForm("hEstateName", ""); string estateId = "";

            if (estate != "")
                estateId = ZLDC.Topo.BLL.Estate.EstateBLL.SelectIdByName(estate);
            string tardetype = _Request.GetStringForm("tradetype", ""); string usage = _Request.GetStringForm("usage", ""); string payType = _Request.GetStringForm("payType", ""); if (payType == "请选择")
            {
                payType = "";
            }
            string type = _Request.GetStringForm("type", ""); if (type == "请选择")
            {
                type = "";
            }
            string Direct = _Request.GetStringForm("Direct", ""); int room = _Request.GetIntForm("room", 0); int room1 = _Request.GetIntForm("room1", 0); int hall = _Request.GetIntForm("hall", 0);
            int restRoom = _Request.GetIntForm("restRoom", 0);
            int balcony = _Request.GetIntForm("balcony", 0);
            int maxFloor = _Request.GetIntForm("maxFloor", 0);
            int minFloor = _Request.GetIntForm("minFloor", 0);
            string houseStyle = _Request.GetStringForm("houseStyle", ""); if (houseStyle == "请选择")
            {
                houseStyle = "";
            }
            string fitment = _Request.GetStringForm("fitment", ""); if (fitment == "请选择")
            {
                fitment = "";
            }
            float minAcreage = _Request.GetIntForm("minAcreage", 0); float maxAcreage = _Request.GetIntForm("maxAcreage", 0); float minPrice = _Request.GetIntForm("minPrice", 0); float maxPrice = _Request.GetIntForm("maxPrice", 0); string priceUnit = _Request.GetStringForm("priceUnit", "");


            int addUId = _Convert.ToInt(_Utility.GetInfoBySession().m_sUserID); string AddUser = _Utility.GetInfoBySession().m_sUserName; int AddDeptId = _Convert.ToInt(_Utility.GetInfoBySession().m_sDeptID); string AddDept = _Utility.GetInfoBySession().m_sDeptName; string owner = _Utility.GetInfoBySession().m_sUserName; int ownerid = _Convert.ToInt(_Utility.GetInfoBySession().m_sUserID); int ownerDeptId = _Convert.ToInt(_Utility.GetInfoBySession().m_sDeptID); string ownerDept = _Utility.GetInfoBySession().m_sDeptName; string ownerTel = _Utility.GetInfoBySession().m_sTel;
            if (AddDeptId == 0 || ownerDeptId == 0)
            {
                _Utility.GoError("权限失效!请重新登陆！");
            }
            int status = _Request.GetIntForm("status", 0); int isSelf = _Request.GetIntForm("isSelf", 0); if (status == 0)
            {
                isSelf = 0;
            }
            else if (status == 1)
            {
                isSelf = 1;
            }


            int dltFlag = 0; string mark1 = _Request.GetStringForm("mark1", "0");
            string mark2 = _Request.GetStringForm("mark2", "");
            string mark3 = _Request.GetStringForm("mark3", "");
            string modifyUser = _Utility.GetInfoBySession().m_sUserName;
            int isValid = 0; string outmsg = "";
            int newid = 0;
            int typeid = _Request.GetIntForm("hTypeID", 0); if (typeid == 2)
            {
                string userNoAndName = _Request.GetStringForm("utxtsub", "");
                int ischange = 1; string userName = string.Empty; string userNo = string.Empty; _Utility.GetUserNoAndUserName(userNoAndName.Trim(), out userName, out userNo);
                ZLDC.Topo.Model.Estate.UserInfo item = ZLDC.Topo.BLL.Estate.UserBLL.GetUserInfoByUserNo(userNo);

                if (item.Usr == "")
                    _Utility.GoError("转介客，接客人不存在！");

                int acceptDeptId = item.Dept_id;
                string acceptDept = item.DeptName;
                int acceptUserId = item.Id;
                string acceptUser = item.Name;

                int count = 0;
                if (_Utility.GetInfoBySession().m_sDeptID.ToString() != acceptDeptId.ToString())
                {
                    count = ZLDC.Topo.BLL.Estate.CustomerBLL.ChangeCustomerCount(acceptDeptId, customerTel);
                    ischange = 1;
                }
                else if (_Utility.GetInfoBySession().m_sDeptID == acceptDeptId.ToString())
                {
                    count = ZLDC.Topo.BLL.Estate.CustomerBLL.ChangeCustomerCountByUserId(acceptUserId, customerTel);
                    ownerDeptId = acceptDeptId;
                    ownerDept = acceptDept;
                    ownerid = acceptUserId;
                    owner = acceptUser;
                    ischange = 2;
                }
                if (count > 0)
                {
                    _Utility.GoError("此转介客已存在该部门，不能转介！");
                }

                if (item.Id > 0)
                {
                    outmsg = ZLDC.Topo.BLL.Estate.CustomerBLL.CustomerSave(Id, customer, customerTel, customerClass, occupation, agent, agentTel, infoFrom, buyingMotive, remark, dId, dname, aId, area, payType, type, Direct, room, room1, hall, restRoom, balcony, maxFloor, minFloor, houseStyle, fitment, minAcreage, maxAcreage, minPrice, maxPrice, priceUnit, addUId, AddUser, AddDeptId, AddDept, owner, ownerid, ownerDeptId, ownerDept, ownerTel, status, isSelf, dltFlag, mark1, mark2, mark3, modifyUser, isValid, tardetype, usage, estate, estateId, ischange, ref newid);
                    outmsg = ZLDC.Topo.BLL.Estate.ChangecustomerLogBLL.p_changeCustomer_log_save(0, newid, AddDeptId, AddDept, addUId, AddUser, acceptDeptId, acceptDept, acceptUserId, acceptUser, 1);
                }

            }
            else
            {
                DataTable dsFiled = null;
                DataSet dsBeFore = null;
                DataSet dsAfter = null;
                string FiledList = "";

                if (Id > 0)
                {
                    ZLDC.Topo.Model.Estate.CustomerInfo info = CacheCustomer.Cache_Detail_Info(Id);

                    if (ZLDC.Common.BaseUser.UserInfo.GetPopedom("修改全部客源") == false)
                    {
                        if (ZLDC.Common.BaseUser.UserInfo.GetPopedom("修改本部客源") == false)
                        {
                            if (ZLDC.Common.BaseUser.UserInfo.GetPopedom("修改本人客源") == false)
                            {
                                _Utility.GoError("对不起，你无权修改此客源！");

                            }
                            else
                            {
                                if (info.Ownerid.ToString() != _Utility.GetInfoBySession().m_sUserID.ToString())
                                {
                                    _Utility.GoError("对不起，你无权修改此客源！");

                                }
                            }
                        }
                        else
                        {
                            if (info.OwnerDeptId.ToString() != _Utility.GetInfoBySession().m_sDeptID.ToString())
                            {
                                _Utility.GoError("对不起，你无权修改此客源！");

                            }
                        }
                    }

                    dsFiled = ZLDC.Topo.BLL.Estate.T_SYS_COL_BLL.p_sys_col_detail_table("t_customer", 1); for (int i = 0; i < dsFiled.Rows.Count; i++)
                    {
                        FiledList += dsFiled.Rows[i]["cName"] + ",";

                    }
                    if (FiledList.Length > 0)
                    {
                        FiledList = FiledList.Substring(0, FiledList.Length - 1);
                    }
                    dsBeFore = ZLDC.Topo.BLL.Estate.CustomerBLL.SelectCustomersById(Id, FiledList);
                }

                outmsg = ZLDC.Topo.BLL.Estate.CustomerBLL.CustomerSave(Id, customer, customerTel, customerClass, occupation, agent, agentTel, infoFrom, buyingMotive, remark, dId, dname, aId, area, payType, type, Direct, room, room1, hall, restRoom, balcony, maxFloor, minFloor, houseStyle, fitment, minAcreage, maxAcreage, minPrice, maxPrice, priceUnit, addUId, AddUser, AddDeptId, AddDept, owner, ownerid, ownerDeptId, ownerDept, ownerTel, status, isSelf, dltFlag, mark1, mark2, mark3, modifyUser, isValid, tardetype, usage, estate, estateId, 0, ref newid);
                if (Id > 0)
                {
                    dsAfter = ZLDC.Topo.BLL.Estate.CustomerBLL.SelectCustomersById(Id, FiledList); string strInfo = "";
                    for (int i = 0; i < dsFiled.Rows.Count; i++)
                    {
                        string BFileValue = dsBeFore.Tables[0].Rows[0][i].ToString();
                        string AFileValue = dsAfter.Tables[0].Rows[0][i].ToString();
                        string FileName = dsFiled.Rows[i]["ccmmt"].ToString();
                        if (BFileValue != AFileValue)
                        {
                            if (FileName == "客户电话" || FileName == "代理人电话")
                            {
                                strInfo += "修改电话[" + BFileValue + "]";
                            }
                            else
                            {
                                strInfo += FileName + ":" + BFileValue + "->" + AFileValue + "；";
                            }
                            if (FileName == "状态")
                            {
                                if (AFileValue == "当前")
                                {
                                    string sStr = "update t_customer set owner='" + _Utility.GetInfoBySession().m_sUserName + "',ownerid='" + _Utility.GetInfoBySession().m_sUserID + "',ownerDept='" + _Utility.GetInfoBySession().m_sDeptName + "',ownerDeptId='" + _Utility.GetInfoBySession().m_sDeptID + "',isSelf=0 where Id=" + Id + "";
                                    using (_Database db = new _Database("estate"))
                                    {
                                        db.ExecuteSql(sStr);
                                    }
                                }
                            }
                        }
                    }
                    if (strInfo != "")
                    {
                        ZLDC.Topo.BLL.Estate.CustomerBLL.p_Customerfollow_save(0, Id, _Convert.ToInt(_Utility.GetInfoBySession().m_sDeptID), _Utility.GetInfoBySession().m_sDeptName, _Convert.ToInt(_Utility.GetInfoBySession().m_sUserID), _Utility.GetInfoBySession().m_sUserName, "修改客源", strInfo, 0, 0);
                    }
                }
            }

            if (Id > 0)
            {
                _Cache.Remove(CacheConst.CACHE_CUSTOMER_DETAIL_JSON + Id.ToString());
                _Cache.Remove(CacheConst.CACHE_CUSTOMER_DETAIL_INFO + Id.ToString());
            }

            if (Id > 0)
                newid = Id;
            if (Id == 0 && outmsg == "添加成功")
            {

                quantificationBLL.UpdateCustomerQuantification(newid, tardetype);
            }
            _Utility.GoError(outmsg);
        }

        public static void CustomerList()
        {
            string json = "";

            int userid = _Convert.ToInt(_Utility.GetInfoBySession().m_sUserID);
            string dept = _Utility.GetInfoBySession().m_sDeptName;
            int deptId = _Convert.ToInt(_Utility.GetInfoBySession().m_sDeptID);
            string station = _Utility.GetInfoBySession().m_sStation; int page = _Request.GetInt("page", 0);
            int pagesize = _Request.GetInt("pagesize", 0);
            int ischangeout = _Request.GetInt("ischangeout", 0);
            int isSelf = _Request.GetInt("isSelf", -1);
            string orderByName = _Request.GetString("orderByName", "ownerDate");
            string orderByType = _Request.GetString("orderByType", "desc");

            string condition = " where dltFlag=0 and isvalid < 2 ";

            if (!ZLDC.Common.BaseUser.UserInfo.GetPopedom("查看全部客源"))
            {
                condition += " and mark1 != 1 and (";
                if (ischangeout == 1)
                {
                    if (_Utility.GetWebConfigSetting("SalesManagerStation").Contains(station))
                    {
                        string deptChildList = CacheUtility.Cache_GetAllChildDept(_Utility.GetInfoBySession().m_sDeptID);
                        condition += "((isSelf=0 and ownerDeptid in(" + deptChildList + ")) or (isSelf=0 and isChange = 2 and addDeptid in(" + deptChildList + ")))";
                    }
                    else
                    {
                        condition += "((isSelf=0 and ownerid = " + userid + ") or (isSelf=0 and isChange = 2 and addUId = " + userid + ")) ";
                    }
                }
                else
                {
                    if (_Utility.GetWebConfigSetting("SalesManagerStation").Contains(station))
                    {
                        string deptChildList = CacheUtility.Cache_GetAllChildDept(_Utility.GetInfoBySession().m_sDeptID);
                        condition += "(isSelf=0 and ownerDeptid in(" + deptChildList + "))";
                    }
                    else
                    {
                        condition += "(isSelf=0 and ownerid = " + userid + ")";
                    }
                }

                condition += " or ";
                string publicCustomerAreas = SessionCustomer.Session_PublicCustomerArea_Get(deptId); if (ischangeout == 1)
                {
                    condition += "((isSelf=1 and ownerDeptId in (" + publicCustomerAreas + ")) or (isSelf=1 and ischange=2 and addDeptId in (" + publicCustomerAreas + ")))";
                }
                else
                {
                    condition += "(isSelf=1 and ownerDeptId in (" + publicCustomerAreas + "))";
                }
                condition += " )";
            }

            int id = _Request.GetInt("id", 0); if (id > 0)
            {
                condition += " and id=" + id;

                json = ZLDC.Topo.BLL.Estate.CustomerBLL.p_customer_list(page, pagesize, condition, orderByName, orderByType);
                HttpContext.Current.Response.Write(json);
            }

            string customertel = _Request.GetString("customertel", ""); if (!string.IsNullOrEmpty(customertel))
            {
                condition += " and customertel like'%" + customertel + "%'";

                json = ZLDC.Topo.BLL.Estate.CustomerBLL.p_customer_list(page, pagesize, condition, orderByName, orderByType);
                HttpContext.Current.Response.Write(json);
            }

            condition += Utility.GetCustomerConditionAdv();

            json = ZLDC.Topo.BLL.Estate.CustomerBLL.p_customer_list(page, pagesize, condition, orderByName, orderByType);

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();
        }

        public static void CustomerListAction()
        {
            string json = "";

            int userid = _Convert.ToInt(_Utility.GetInfoBySession().m_sUserID);
            string dept = _Utility.GetInfoBySession().m_sDeptName;
            string station = _Utility.GetInfoBySession().m_sStation; int page = _Request.GetInt("page", 0);
            int pagesize = _Request.GetInt("pagesize", 0);

            string condition = " where dltFlag=0 and isvalid < 2 ";

            if (!ZLDC.Common.BaseUser.UserInfo.GetPopedom("查看全部客源"))
            {
                if (_Utility.GetWebConfigSetting("SalesManagerStation").Contains(station))
                {
                    string deptChildList = CacheUtility.Cache_GetAllChildDept(_Utility.GetInfoBySession().m_sDeptID);
                    condition += " and (ownerDeptid in(" + deptChildList + "))";
                }
                else
                {
                    condition += " and (ownerid = " + userid + " or (isChange = 2 and addUId = " + userid + ")) ";
                }
            }

            int id = _Request.GetInt("id", 0); if (id > 0)
            {
                condition += " and id=" + id;

                json = ZLDC.Topo.BLL.Estate.CustomerBLL.p_customer_list_action(userid, page, pagesize, condition);
                HttpContext.Current.Response.Write(json);
            }

            string customertel = _Request.GetString("customertel", ""); if (!string.IsNullOrEmpty(customertel))
            {
                condition += " and customertel='" + customertel + "'";

                json = ZLDC.Topo.BLL.Estate.CustomerBLL.p_customer_list_action(userid, page, pagesize, condition);
                HttpContext.Current.Response.Write(json);
            }

            condition += Utility.GetCustomerConditionAdv();

            json = ZLDC.Topo.BLL.Estate.CustomerBLL.p_customer_list_action(userid, page, pagesize, condition);

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();
        }

        public static void CustomerDetail()
        {
            int id = _Request.GetInt("id", 0);

            string json = CacheCustomer.Cache_Detail_Json(id);

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();
        }

        public static void CustomerDel()
        {
            int id = 0;
            string outmsg = "";
            string[] IDList = _Utility.GetStringBySplit(_Request.GetString("id"), '|');
            string SalesManagerStation = _Utility.GetWebConfigSetting("SalesManagerStation");

            if (IDList != null && IDList.Length > 0)
            {
                for (int i = 0; i < IDList.Length; i++)
                {
                    id = _Convert.ToInt(IDList[i], 0);

                    ZLDC.Topo.Model.Estate.CustomerInfo info = ZLDC.Topo.BLL.Estate.CustomerBLL.p_customer_detail(id);
                    if (info.IsSelf == 0)
                    {

                        if ((info.OwnerDeptId.ToString() == _Utility.GetInfoBySession().m_sDeptID && ZLDC.Common.BaseUser.UserInfo.GetPopedom("删除客源") && info.IsChange == 0) || ZLDC.Common.BaseUser.UserInfo.GetPopedom("删除全部客源"))
                        {

                            outmsg = ZLDC.Topo.BLL.Estate.CustomerBLL.CustomerDel(id);


                            ZLDC.Topo.BLL.Estate.OperationlogBLL.p_operationlog_insert("t_customer", id, 4, "删除客源");
                        }
                        else if (SalesManagerStation.Contains(_Utility.GetInfoBySession().m_sStation))
                        {
                            string GetParentIdById = ZLDC.DAL.Estate.DeptDAL.GetParentIdById(info.OwnerDeptId);

                            if (GetParentIdById == _Utility.GetInfoBySession().m_sDeptID && ZLDC.Common.BaseUser.UserInfo.GetPopedom("删除客源") && info.IsChange == 0)
                            {
                                outmsg = ZLDC.Topo.BLL.Estate.CustomerBLL.CustomerDel(id);

                                ZLDC.Topo.BLL.Estate.OperationlogBLL.p_operationlog_insert("t_customer", id, 4, "删除客源");
                            }
                            else
                            {
                                outmsg = "对不起，您无权删除该客源！";
                            }

                        }
                        else
                        {
                            outmsg = "对不起，您无权删除该客源！";
                        }
                    }
                    else
                    {
                        outmsg = ZLDC.Topo.BLL.Estate.CustomerBLL.CustomerDel(id);
                        ZLDC.Topo.BLL.Estate.OperationlogBLL.p_operationlog_insert("t_customer", id, 4, "删除客源");
                    }
                }
            }

            if (id > 0)
            {
                _Cache.RemoveLike(CacheConst.CACHE_CUSTOMER_FOLLOW_JSON + id);
                _Cache.Remove(CacheConst.CACHE_CUSTOMER_DETAIL_JSON + id.ToString());
                _Cache.Remove(CacheConst.CACHE_CUSTOMER_DETAIL_INFO + id.ToString());
            }

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(outmsg);
            HttpContext.Current.Response.End();
        }

        public static void CustomerCheckListAction()
        {
            string json = "";

            int deptId = _Convert.ToInt(_Utility.GetInfoBySession().m_sDeptID);
            string station = _Utility.GetInfoBySession().m_sStation; int page = _Request.GetInt("page", 0);
            int pagesize = _Request.GetInt("pagesize", 0);


            string custName = _Request.GetString("custname", ""); int Custid = _Request.GetInt("custid", 0); bool flag = _Request.GetBool("flag", false);
            string orderByName = _Request.GetString("orderByName", "followUpDate");
            string orderByType = _Request.GetString("orderByType", "desc");

            string condition = " where dltFlag=0 and mark1='1' ";

            if (custName != "")
            {
                condition += " and customer='" + custName + "' ";
            }

            if (Custid > 0)
            {
                condition += " and id='" + Custid + "' ";
            }

            if (station == "分行经理" || station == "业务主任")
            {
                condition += " and ownerdeptid=" + _Utility.GetInfoBySession().m_sDeptID + " ";
            }
            else if (station == "区域经理" || station == "分区经理")
            {
                string IdList = CacheUtility.Cache_GetAllChildDept(_Utility.GetInfoBySession().m_sDeptID);
                if (flag == true) condition += " and ownerdeptid in(" + IdList + ") and DATEDIFF(dd, modifydate, GETDATE())=0 ";
                else
                    condition += " and ownerdeptid in(" + IdList + ") and DATEDIFF(dd, modifydate, GETDATE())>=1 ";
            }
            else if (ZLDC.Common.BaseUser.UserInfo.GetPopedom("查看全部客源"))
            {
                if (flag == true) condition += "  and DATEDIFF(dd, modifydate, GETDATE())=1 ";
                else
                    condition += "";
            }
            else
            {
                condition += " and ownerid=" + _Utility.GetInfoBySession().m_sUserID + " ";
            }



            json = ZLDC.Topo.BLL.Estate.CustomerBLL.p_customer_list(page, pagesize, condition, orderByName, orderByType);

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();

        }

        public static void CustomerChange()
        {
            int deptid = _Convert.ToInt(_Utility.GetInfoBySession().m_sDeptID, 0);
            string deptname = _Utility.GetInfoBySession().m_sDeptName;
            int userid = _Convert.ToInt(_Utility.GetInfoBySession().m_sUserID, 0);
            string username = _Utility.GetInfoBySession().m_sUserName;
            string remark = "";

            int id = 0;
            string outmsg = "";
            int isself = _Request.GetInt("isself", 0);

            if (isself == 0)
                remark = "申请转私客";
            else
                remark = "转公客";

            string[] IDList = _Utility.GetStringBySplit(_Request.GetString("id"), '|');

            if (IDList != null && IDList.Length > 0)
            {
                for (int i = 0; i < IDList.Length; i++)
                {
                    id = _Convert.ToInt(IDList[i], 0);
                    outmsg = ZLDC.Topo.BLL.Estate.CustomerBLL.CustomerChange(id, isself);

                    if (outmsg.Contains("成功"))
                    {
                        ZLDC.Topo.BLL.Estate.CustomerBLL.p_Customerfollow_save(0, id, deptid, deptname, userid, username, "转客", remark, 0, 0);
                    }

                    if (id > 0)
                    {
                        _Cache.RemoveLike(CacheConst.CACHE_CUSTOMER_FOLLOW_JSON + id);
                        _Cache.Remove(CacheConst.CACHE_CUSTOMER_DETAIL_JSON + id.ToString());
                        _Cache.Remove(CacheConst.CACHE_CUSTOMER_DETAIL_INFO + id.ToString());
                    }
                }
            }

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(outmsg);
            HttpContext.Current.Response.End();
        }

        public static void CustomerChangeSelf()
        {
            int deptid = _Convert.ToInt(_Utility.GetInfoBySession().m_sDeptID, 0);
            string deptname = _Utility.GetInfoBySession().m_sDeptName;
            int userid = _Convert.ToInt(_Utility.GetInfoBySession().m_sUserID, 0);
            string username = _Utility.GetInfoBySession().m_sUserName;
            string remark = "转客成功";

            int isself = 0;
            string[] IDList = _Utility.GetStringBySplit(_Request.GetString("id"), '|');

            if (IDList != null && IDList.Length > 0)
            {
                int id = 0;
                for (int i = 0; i < IDList.Length; i++)
                {
                    id = _Convert.ToInt(IDList[i], 0);
                    if (ZLDC.Topo.BLL.Estate.CustomerBLL.CustomerChangeSelf(id, isself) > 0)
                    {
                        ZLDC.Topo.BLL.Estate.CustomerBLL.p_Customerfollow_save(0, id, deptid, deptname, userid, username, "转私客", remark, 0, 0);
                    }

                    if (id > 0)
                    {
                        _Cache.RemoveLike(CacheConst.CACHE_CUSTOMER_FOLLOW_JSON + id);
                        _Cache.Remove(CacheConst.CACHE_CUSTOMER_DETAIL_JSON + id.ToString());
                        _Cache.Remove(CacheConst.CACHE_CUSTOMER_DETAIL_INFO + id.ToString());
                    }
                }
            }

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(remark);
            HttpContext.Current.Response.End();
        }

        public static void CustomerFollowSave()
        {
            int Id = 0;
            int CustomerId = _Request.GetIntForm("customerId", 0);
            int fDeptId = _Convert.ToInt(_Utility.GetInfoBySession().m_sDeptID);
            string fDept = _Utility.GetInfoBySession().m_sDeptName;
            int fUserId = _Convert.ToInt(_Utility.GetInfoBySession().m_sUserID);
            string fUser = _Utility.GetInfoBySession().m_sUserName;
            string fType = _Request.GetStringForm("followType", "");

            if (fType.Equals("带看房"))
            {
                ZLDC.Topo.Model.Estate.CustomerInfo info = ZLDC.Topo.BLL.Estate.CustomerBLL.p_customer_detail(CustomerId);
                if (info.Tradetype.Equals("求购"))
                    fType = "带看售房";
                else
                    fType = "带看租房";


            }

            string fContent = _Request.GetStringForm("fcontent", "");
            string estate = _Request.GetStringForm("txtEstate", "");
            if (estate != "")
            {
                fContent += "[所看房源：]" + estate.Trim();
            }
            int dltFlag = 0;
            int fHousingId = 0;
            int IsSee = _Request.GetIntForm("IsSee", 0);
            if (IsSee > 0)
            {
                fHousingId = _Request.GetIntForm("housingid", 0);
            }
            string outmsg = "";
            outmsg = ZLDC.Topo.BLL.Estate.CustomerBLL.p_Customerfollow_save(Id, CustomerId, fDeptId, fDept, fUserId, fUser, fType, fContent, dltFlag, fHousingId);


            if (CustomerId > 0)
            {
                _Cache.RemoveLike(CacheConst.CACHE_CUSTOMER_FOLLOW_JSON + CustomerId);
                _Cache.Remove(CacheConst.CACHE_CUSTOMER_DETAIL_JSON + CustomerId.ToString());
                _Cache.Remove(CacheConst.CACHE_CUSTOMER_DETAIL_INFO + CustomerId.ToString());
            }

            int count = 0;
            if (fType == "带看售房" || fType == "带看租房")
            {
                string itemValue = ZLDC.Topo.BLL.Estate.SystemOptionBLL.GetOption("同一个客户一天内看房算多次").ToString();

                if (itemValue == "0")
                {
                    quantificationBLL.UpdateCustomerFollowQuantification(fType);

                }
                else
                {
                    count = ZLDC.Topo.BLL.Estate.CustomerBLL.CustomerFollowByTypeOrDate(CustomerId);
                    if (count == 1)
                    {
                        quantificationBLL.UpdateCustomerFollowQuantification(fType);

                    }
                    else
                        quantificationBLL.UpdateCustomerFollowQuantification("");
                }

                ZLDC.Topo.BLL.Estate.CustomerBLL.UpdateLookCustomerCount(CustomerId);
            }
            else
            {
                quantificationBLL.UpdateCustomerFollowQuantification(fType);


                int typeid = 0;
                int EarnestMoney = 0;
                int talks = 0;
                int afterservice = 0;
                if (fType == "诚意金")
                {
                    typeid = 21;
                }
                else if (fType == "摆台")
                {
                    typeid = 22;
                }
                else if (fType == "成交后服务")
                {
                    typeid = 23;
                }
                if (quantificationBLL.isExitByTypeId(typeid, CustomerId) == 0)
                {
                    switch (typeid)
                    {
                        case 21:
                            EarnestMoney = 1;
                            break;
                        case 22:
                            talks = 1;
                            break;
                        case 23:
                            afterservice = 1;
                            break;
                    }
                    quantificationBLL.UpdateCustomerOrHousingQuantification(typeid, CustomerId, 0, 0, EarnestMoney, talks, afterservice);
                }




            }

            HttpContext.Current.Response.Write("<script>window.close();</script>");

        }

        public static void CustomerFollowSave1()
        {
            int Id = 0;
            int CustomerId = _Request.GetInt("customerId", 0);
            int fDeptId = _Request.GetInt("fdeptId", 0);
            string fDept = _Request.GetString("fdept", "");
            int fUserId = _Request.GetInt("fUserId", 0);
            string fUser = _Request.GetString("fUser", "");

            string paperNo = _Request.GetString("paperNo", "");
            string fType = _Request.GetString("followType", "");

            if (fType.Equals("带看房"))
            {
                ZLDC.Topo.Model.Estate.CustomerInfo info = ZLDC.Topo.BLL.Estate.CustomerBLL.p_customer_detail(CustomerId);
                if (info.Tradetype.Equals("求购"))
                    fType = "带看售房";
                else
                    fType = "带看租房";



            }
            string customerClass = _Request.GetString("customerClass", "");

            string fContent = _Request.GetString("fcontent", "");
            string estate = _Request.GetString("txtEstate", "");
            if (estate != "")
            {
                fContent += "[所看房源：]" + estate.Trim();
            }
            if (paperNo != "")
                fContent += "，看楼纸编号：" + paperNo;


            int dltFlag = 0;
            string fHousingId = "0"; ;
            int IsSee = _Request.GetInt("IsSee", 0);
            if (IsSee > 0)
            {
                fHousingId = _Request.GetString("housingid", "0");
            }

            string lookUserName = _Request.GetString("userNameList", "");
            string lookUserId = _Request.GetString("userIdList", "");
            string[] userNameList = null;
            int userNameListLength = 0;
            if (lookUserName != "")
            {
                fContent += ",看楼人员：" + lookUserName;
                userNameList = lookUserName.Split(',');
                userNameListLength = userNameList.Length;

            }





            string[] userIdList = null;
            int userIdListLength = 0;
            if (lookUserId != "")
            {
                userIdList = lookUserId.Split(',');
                userIdListLength = userIdList.Length;
            }


            string[] hIdList = null;
            int hIdListLength = 0;
            if (fHousingId != "0" || fHousingId != "")
            {
                hIdList = fHousingId.Split(',');
                hIdListLength = hIdList.Length;
            }


            string[] hNameList = estate.Split(',');
            string HousingIdList = "";

            for (int i = 1; i < hIdListLength; i++)
            {
                HousingIdList += hIdList[i].ToString();
                if (i < hIdList.Length - 1)
                    HousingIdList += ",";
            }

            string outmsg = "";
            int newId = 0;




            outmsg = ZLDC.Topo.BLL.Estate.CustomerBLL.p_Customerfollow_save(Id, CustomerId, fDeptId, fDept, fUserId, fUser, fType, fContent, dltFlag, _Convert.ToInt(hIdList[0]));

            if (newId > 0)
            {
                ZLDC.Topo.Model.Estate.CustomerInfo info = ZLDC.Topo.BLL.Estate.CustomerBLL.p_customer_detail(CustomerId);

                if (info.CustomerClass != customerClass)
                {
                    ZLDC.Topo.BLL.Estate.CustomerBLL.UpdateChangeCustomerClasss(customerClass, CustomerId);
                }

                if (paperNo != "")
                {
                    ZLDC.Topo.BLL.Estate.ShowFloorPaperBLL.p_showFloorPaper_save(1, paperNo, 0, 0, "", 0, "", 1);
                }
                for (int i = 0; i < hIdListLength; i++)
                {
                    ZLDC.Topo.BLL.Estate.CustomerBLL.p_Customerfollow_housingMore_save(newId, _Convert.ToInt(hIdList[i]), hNameList[i].ToString());
                }

                for (int i = 0; i < userNameListLength; i++)
                {
                    ZLDC.Topo.Model.Estate.UserInfo userinfo = ZLDC.Topo.BLL.Estate.UserBLL.GetUserInfoByUserID(_Convert.ToInt(userIdList[i]));

                    ZLDC.Topo.BLL.Estate.CustomerBLL.p_Customerfollow_customerMore_save(newId, _Convert.ToInt(userIdList[i]), userNameList[i], userinfo.Dept_id);
                }

                outmsg = "添加成功";
            }

            if (CustomerId > 0)
            {
                _Cache.RemoveLike(CacheConst.CACHE_CUSTOMER_FOLLOW_JSON + CustomerId);
                _Cache.Remove(CacheConst.CACHE_CUSTOMER_DETAIL_JSON + CustomerId.ToString());
                _Cache.Remove(CacheConst.CACHE_CUSTOMER_DETAIL_INFO + CustomerId.ToString());
            }


            int count = 0;
            if (fType == "带看售房" || fType == "带看租房")
            {
                string itemValue = ZLDC.Topo.BLL.Estate.SystemOptionBLL.GetOption("同一个客户一天内看房算多次").ToString();

                if (itemValue == "0")
                {
                    quantificationBLL.UpdateCustomerFollowQuantification(fType);

                }
                else
                {
                    count = ZLDC.Topo.BLL.Estate.CustomerBLL.CustomerFollowByTypeOrDate(CustomerId);
                    if (count == 1)
                    {
                        float totalSum = 0;
                        double total = 1;
                        double pCount = _Convert.ToDouble((userIdListLength + 1).ToString());
                        for (int i = 0; i < userIdListLength; i++)
                        {
                            ZLDC.Topo.Model.Estate.UserInfo userinfo = ZLDC.Topo.BLL.Estate.UserBLL.GetUserInfoByUserID(_Convert.ToInt(userIdList[i]));


                            totalSum = float.Parse((total / pCount).ToString("f2"));

                            quantificationBLL.UpdateCustomerFollowQuantification(fType, totalSum, 0, _Convert.ToInt(userinfo.Id.ToString()), userinfo.Name, _Convert.ToInt(userinfo.Dept_id.ToString()), userinfo.DeptName);
                        }
                        if (totalSum == 0)
                            totalSum = 1;

                        int userId = _Convert.ToInt(_Utility.GetInfoBySession().m_sUserID, 0);
                        int deptId = _Convert.ToInt(_Utility.GetInfoBySession().m_sDeptID, 0);
                        string deptName = _Utility.GetInfoBySession().m_sDeptName;
                        string userName = _Utility.GetInfoBySession().m_sUserName;

                        quantificationBLL.UpdateCustomerFollowQuantification(fType, totalSum, 1, userId, userName, deptId, deptName);

                    }
                    else
                        quantificationBLL.UpdateCustomerFollowQuantification("");
                }
                ZLDC.Topo.BLL.Estate.CustomerBLL.UpdateLookCustomerCount(CustomerId);
            }
            else
            {
                quantificationBLL.UpdateCustomerFollowQuantification(fType);


                int typeid = 0;
                int EarnestMoney = 0;
                int talks = 0;
                int afterservice = 0;
                if (fType == "诚意金")
                {
                    typeid = 21;
                }
                else if (fType == "摆台")
                {
                    typeid = 22;
                }
                else if (fType == "成交后服务")
                {
                    typeid = 23;
                }
                if (quantificationBLL.isExitByTypeId(typeid, CustomerId) == 0)
                {
                    switch (typeid)
                    {
                        case 21:
                            EarnestMoney = 1;
                            break;
                        case 22:
                            talks = 1;
                            break;
                        case 23:
                            afterservice = 1;
                            break;
                    }
                    quantificationBLL.UpdateCustomerOrHousingQuantification(typeid, CustomerId, 0, 0, EarnestMoney, talks, afterservice);
                }




            }


            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(outmsg);
            HttpContext.Current.Response.End();
        }

        public static void CustomerAlertSave()
        {
            int Id = 0;
            int customerId = _Request.GetIntForm("customerId", 0);
            string AlertType = _Request.GetStringForm("AlertType", "");
            string AlertContent = _Request.GetStringForm("AlertContent", "");
            string scope = _Request.GetStringForm("AlertScope", "");
            int AlertScope = 0;
            if (scope == "本人")
            {
                AlertScope = 1;
            }
            else if (scope == "本部")
            {
                AlertScope = 2;
            }

            string time = _Request.GetStringForm("AlertDate", "") + " ";
            time += DateTime.Now.ToString("HH:mm:ss");
            DateTime AlertDate = Convert.ToDateTime(time);
            int AddDeptId = _Convert.ToInt(_Utility.GetInfoBySession().m_sDeptID);
            string AddDept = _Utility.GetInfoBySession().m_sDeptName;
            int AddUserId = _Convert.ToInt(_Utility.GetInfoBySession().m_sUserID);
            string AddUser = _Utility.GetInfoBySession().m_sUserName;
            int dFlag = 0; int dDeptId = 0; string dDept = ""; int dUserId = 0; string dUser = ""; int dltFlag = 0; string outmsg = "";
            outmsg = ZLDC.Topo.BLL.Estate.CustomerBLL.p_customerAlert_save(Id, customerId, AlertType, AlertContent, AlertScope, AlertDate, AddDeptId, AddDept, AddUserId, AddUser, dFlag, dDeptId, dDept, dUserId, dUser, dltFlag);

            quantificationBLL.UpdateCustomerAlertQuantification(AlertType);

            HttpContext.Current.Response.Write("<script>window.close();</script>");
        }

        public static void SelectCustomerFollow()
        {
            int page = _Request.GetInt("page", 0);
            int pagesize = _Request.GetInt("pagesize", 0);
            int customerId = _Request.GetInt("id", 0);
            int deptid = _Request.GetInt("deptid", 0);
            int refresh = _Request.GetInt("refresh", 0);
            if (refresh == 1)
                CacheCustomerFollow.Cache_Follow_Json_Clear(page, pagesize, customerId, deptid);

            string json = CacheCustomerFollow.Cache_Follow_Json(page, pagesize, customerId, deptid);

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();
        }

        public static void SelectCustomerAlert()
        {
            int page = _Request.GetInt("page", 0);
            int pagesize = _Request.GetInt("pagesize", 0);
            int cutomerId = _Request.GetInt("id", 0);
            string json = ZLDC.Topo.BLL.Estate.CustomerBLL.p_customerAlert_list(page, pagesize, cutomerId, _Convert.ToInt(_Utility.GetInfoBySession().m_sUserID));
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();
        }

        public static void p_CustomerAlert_Update()
        {
            string[] IDList = _Utility.GetStringBySplit(_Request.GetString("id"), '|');
            int id = 0;
            int json = 0;
            int dflag = 1; int deptid = _Convert.ToInt(_Utility.GetInfoBySession().m_sDeptID);
            string dept = _Utility.GetInfoBySession().m_sDeptName;
            int duserid = _Convert.ToInt(_Utility.GetInfoBySession().m_sUserID);
            string duser = _Utility.GetInfoBySession().m_sUserName;


            for (int i = 0; i < IDList.Length; i++)
            {
                id = Convert.ToInt32(IDList[i]);
                json = ZLDC.Topo.BLL.Estate.CustomerBLL.p_CustomerAlert_update(id, dflag, deptid, dept, duserid, duser);

            }
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();
        }

        #region 我的客源

        private static void MyCustomer()
        {
            int userid = _Convert.ToInt(_Utility.GetInfoBySession().m_sUserID);
            string station = _Utility.GetInfoBySession().m_sStation;
            string condition = " where dltFlag=0 and isvalid < 2 and isself =0 ";

            if (_Utility.GetWebConfigSetting("SalesManagerStation").Contains(station))
            {
                string deptid = _Utility.GetInfoBySession().m_sDeptID; string deptChildList = CacheUtility.Cache_GetAllChildDept(deptid);

                condition += " and ownerdeptid in (" + deptChildList + ")";
            }
            else
                condition += " and ownerid =" + userid;

            string json = ZLDC.Topo.BLL.Estate.CustomerBLL.SelectMyCustomer(5, condition);

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();
        }

        public static void p_MyCustomerList()
        {
            int userid = _Convert.ToInt(_Utility.GetInfoBySession().m_sUserID); string station = _Utility.GetInfoBySession().m_sStation;
            int page = _Request.GetInt("page", 0);
            int pagesize = _Request.GetInt("pagesize", 0);

            string orderByName = _Request.GetString("orderByName", "ownerdate");
            string orderByType = _Request.GetString("orderByType", "desc");
            int ischangeout = _Request.GetInt("ischangeout", 0);
            string json = "";

            string condition = " where dltFlag=0 and isvalid < 2 and [status] < 2  ";

            if (ischangeout == 1)
            {
                if (_Utility.GetWebConfigSetting("SalesManagerStation").Contains(station))
                {
                    string deptChildList = CacheUtility.Cache_GetAllChildDept(_Utility.GetInfoBySession().m_sDeptID);
                    condition += " and ((ownerdeptid in(" + deptChildList + ")) or (ischange=2 and adddeptid in(" + deptChildList + ")) )";
                }
                else
                    condition += " and ((ownerid =" + userid + ") or (ischange=2 and addUid =" + userid + ")) ";
            }
            else
            {
                if (_Utility.GetWebConfigSetting("SalesManagerStation").Contains(station))
                {
                    string deptChildList = CacheUtility.Cache_GetAllChildDept(_Utility.GetInfoBySession().m_sDeptID);
                    condition += " and ownerdeptid in(" + deptChildList + ")";
                }
                else
                    condition += " and ownerid =" + userid;
            }
            int id = _Request.GetInt("id", 0); if (id > 0)
            {
                condition += " and id=" + id;

                json = ZLDC.Topo.BLL.Estate.CustomerBLL.p_customer_list(page, pagesize, condition, orderByName, orderByType);
                HttpContext.Current.Response.Write(json);
            }

            string customertel = _Request.GetString("customertel", ""); if (!string.IsNullOrEmpty(customertel))
            {
                condition += " and customertel like '%" + customertel + "%'";

                json = ZLDC.Topo.BLL.Estate.CustomerBLL.p_customer_list(page, pagesize, condition, orderByName, orderByType);
                HttpContext.Current.Response.Write(json);
            }

            condition += Utility.GetCustomerCondition();

            json = ZLDC.Topo.BLL.Estate.CustomerBLL.p_customer_list(page, pagesize, condition, orderByName, orderByType);

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();
        }

        #endregion

        public static string getsale(string price)
        {
            switch (price)
            {
                case "1000万及以上":
                    price = " and totalprice>=1000 ";
                    break;
                case "800万至1000万":
                    price = " and  totalprice>=800 and totalprice<=1000 ";
                    break;
                case "500万至800万":
                    price = " and  totalprice>=500 and totalprice<=800 ";
                    break;
                case "300万至500万":
                    price = " and  totalprice>=300 and totalprice<=500 ";
                    break;
                case "100万至300万":
                    price = " and  totalprice>=100 and totalprice<=300 ";
                    break;
                case "100万及以下":
                    price = " and  totalprice<=100  ";
                    break;

                case "1万及以上":
                    price = " and leaseprice>=10000 ";
                    break;
                case "8000至10000":
                    price = " and  leaseprice>=8000 and leaseprice<=10000 ";
                    break;
                case "5000至8000万":
                    price = " and  leaseprice>=5000 and leaseprice<=8000 ";
                    break;
                case "3000至5000":
                    price = " and  leaseprice>=3000 and leaseprice<=5000 ";
                    break;
                case "1000至3000":
                    price = " and  leaseprice>=1000 and leaseprice<=3000 ";
                    break;
                case "1000及以下":
                    price = " and  leaseprice<=1000  ";
                    break;

                case "144平以上":
                    price = " and acreage>144 ";
                    break;
                case "90平至144平":
                    price = " and  acreage>90 and acreage<144 ";
                    break;
                case "90平及以下":
                    price = " and  acreage<=90  ";
                    break;
            }
            return price;
        }

        public static void p_CustomerReportList()
        {
            int page = _Request.GetInt("page", 0);
            int pagesize = _Request.GetInt("pagesize", 0);
            string StratTime = _Request.GetString("startTime", "");
            string EndTIME = _Request.GetString("EndTime", "");
            string deptId = _Request.GetString("deptname", "");
            string USERID = _Request.GetString("UserName", "");
            string housingname = _Request.GetString("housingname", "");
            string eid = _Request.GetString("eid", "0");
            string sale = _Request.GetString("sale", "");

            string ftype = _Request.GetString("ftype");
            if (StratTime == "" && EndTIME == "")
            {
                StratTime = DateTime.Now.ToString("yyyy-MM-dd");

                EndTIME = DateTime.Now.ToString("yyyy-MM-dd");
            }

            string IdList1 = ""; if (_Convert.ToInt(deptId.ToString()) > 0)
            {
                DataTable dt = ZLDC.DAL.Estate.DeptDAL.getGetAllChildrenDept(deptId);
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if (dt.Rows[i]["id"].ToString() != "")
                    {
                        IdList1 += dt.Rows[i]["id"].ToString() + ",";
                    }
                }
                if (IdList1 != "")
                {
                    IdList1 = IdList1.Substring(0, IdList1.Length - 1);
                }
            }
            string condition = "  where 1=1 ";
            string station = _Utility.GetInfoBySession().m_sStation;
            if (ZLDC.Common.BaseUser.UserInfo.GetPopedom("查看全部客源跟进"))
            {
                if (IdList1 != "")
                {
                    condition += " and fdeptid in(" + IdList1 + ") ";
                }
            }
            else
            {
                if (_Utility.GetWebConfigSetting("SalesManagerStation").Contains(station))
                {
                    string IdList = CacheUtility.Cache_GetAllChildDept(_Utility.GetInfoBySession().m_sDeptID);

                    if (deptId != "")
                    {
                        if (ftype == "带看租房" || ftype == "带看售房" || ftype.Equals("带看房"))
                            condition += " and ( fdeptid in(" + IdList1 + ") or Id in (select customerFollowId From t_Customerfollow_customerMore where teamworkDeptId in (" + IdList1 + "))) and (fdeptid in(" + IdList + ") or Id in(select customerFollowId From t_Customerfollow_customerMore where teamworkDeptId in (" + IdList + "))) ";
                        else
                            condition += " and fdeptid in(" + IdList1 + ") and fdeptid in(" + IdList + ") ";

                    }
                    else
                    {
                        if (ftype == "带看租房" || ftype == "带看售房" || ftype.Equals("带看房"))
                            condition += " and fdeptid in(" + IdList + ") ";
                        else
                            condition += " and (fdeptid in(" + IdList + ") or Id in(select customerFollowId From t_Customerfollow_customerMore where teamworkDeptId in (" + IdList + "))) ";

                    }

                }
                else
                {


                    if (ftype == "带看租房" || ftype == "带看售房")
                    {
                        condition += " and ( fUserId=" + _Utility.GetInfoBySession().m_sUserID + " or Id in(select customerFollowId From t_Customerfollow_customerMore where teamworkUserId='" + _Utility.GetInfoBySession().m_sUserID + "'))";
                    }
                    else
                    {
                        condition += " and fUserId=" + _Utility.GetInfoBySession().m_sUserID + "";
                    }
                }

            }

            if (StratTime != "" && EndTIME != "")
            {
                condition += "  and fdate between '" + StratTime + " 00:00:00" + "' and '" + EndTIME + " 23:59:59" + "' ";
            }

            if (housingname != "")
            {
                condition += " and eid =" + eid + "";
            }
            if (sale != "")
            {
                condition += getsale(sale);
            }


            if (_Convert.ToInt(USERID, 0) > 0 && (ftype == "带看租房" || ftype == "带看售房"))
            {

                condition += " and (fUserId='" + USERID + "' or Id in(select customerFollowId From t_Customerfollow_customerMore where teamworkUserId='" + USERID + "')) ";
            }
            else if (_Convert.ToInt(USERID, 0) > 0)
            {
                condition += " AND fUserId='" + USERID + "' ";
            }
            else
            {

                if (USERID != "")
                {
                    string userName = string.Empty; string userNo = string.Empty; int userId = 0; _Utility.GetUserNoAndUserName(USERID.Trim(), out userName, out userNo);
                    if (userName == "")
                    {
                        condition += " AND fUserId='" + USERID + "' ";
                    }
                    else
                    {
                        userId = ZLDC.Topo.BLL.Estate.UserBLL.GetUserIDByUserNo(userNo);
                        condition += " AND fUserId='" + userId.ToString() + "' ";
                    }
                }
            }

            if (!ftype.Equals("all"))
            {
                if (!ftype.Equals(""))
                {
                    if (ftype.Equals("带看房"))
                    {
                        condition += " and ftype in ('带看租房','带看售房')";
                    }
                    else
                    {
                        condition += " and ftype='" + ftype + "'";
                    }
                }
                else
                {
                    string typeList = "";
                    DataTable dtParam = SystemParamBLL.ListByType("跟进方式(客)");
                    for (int i = 0; i < dtParam.Rows.Count; i++)
                    {

                        string itemName = dtParam.Rows[i]["item"].ToString();
                        if (itemName == "带看房")
                        {
                            typeList += "'带看租房','带看售房',";
                        }
                        else
                        {
                            typeList += "'" + itemName + "',";
                        }

                    }
                    if (typeList != "")
                    {
                        typeList = typeList.Substring(0, typeList.Length - 1);
                    }

                    condition += " and ftype in (" + typeList + ")";
                }
            }




            string json = ZLDC.Topo.BLL.Estate.CustomerBLL.p_CustomerfollowReport_list_table(page, pagesize, condition);

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();
        }

        public static void p_CustomerAlertReportList()
        {
            int page = _Request.GetInt("page", 0);
            int pagesize = _Request.GetInt("pagesize", 0);
            string StratTime = _Request.GetString("startTime", "");
            string EndTIME = _Request.GetString("EndTime", "");
            string deptid = _Request.GetString("deptname", "");
            string USERID = _Request.GetString("UserName", "");
            string ftype = _Request.GetString("ftype");

            string IdList1 = ""; if (_Convert.ToInt(deptid) > 0)
            {

                DataTable dt = ZLDC.DAL.Estate.DeptDAL.getGetAllChildrenDept(deptid);
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if (dt.Rows[i]["id"].ToString() != "")
                    {
                        IdList1 += dt.Rows[i]["id"].ToString() + ",";
                    }
                }
                if (IdList1 != "")
                    IdList1 = IdList1.Substring(0, IdList1.Length - 1);
            }
            string condition = "  where 1=1 "; string station = _Utility.GetInfoBySession().m_sStation;

            if (ZLDC.Common.BaseUser.UserInfo.GetPopedom("查看全部待看提醒"))
            {
                if (IdList1 != "")
                    condition += " and AddDeptId in(" + IdList1 + ") ";
            }
            else
            {
                if (_Utility.GetWebConfigSetting("SalesManagerStation").Contains(station))
                {
                    string IdList = CacheUtility.Cache_GetAllChildDept(_Utility.GetInfoBySession().m_sDeptID);

                    if (deptid != "")
                        condition += " and AddDeptId in(" + IdList1 + ")   and AddDeptId in(" + IdList + ") ";
                    else
                        condition += " and AddDeptId in(" + IdList + ") ";
                }
                else
                    condition += "   AND AddUserId='" + _Utility.GetInfoBySession().m_sUserID + "'";

                if (StratTime != "" && EndTIME == "")
                    condition += " and AddDate like '" + StratTime + "' ";

                if (EndTIME != "" && StratTime == "")
                    condition += " and AddDate like '" + EndTIME + "' ";
            }

            if (StratTime != "" && EndTIME != "")
                condition += "  and AddDate >= '" + StratTime + " 00:00:00' and AddDate <= '" + EndTIME + " 23:59:59' ";


            if (_Convert.ToInt(USERID, 0) > 0)
                condition += " AND AddUserId='" + USERID + "' ";
            else
            {

                if (USERID != "")
                {
                    string userName = string.Empty; string userNo = string.Empty; int userId = 0; _Utility.GetUserNoAndUserName(USERID.Trim(), out userName, out userNo);
                    if (userName == "")
                    {
                        condition += " AND AddUserId='" + USERID + "' ";
                    }
                    else
                    {
                        userId = ZLDC.Topo.BLL.Estate.UserBLL.GetUserIDByUserNo(userNo);
                        condition += " AND AddUserId='" + userId.ToString() + "' ";
                    }
                }
            }
            if (!ftype.Equals(""))
                condition += " and alerttype='" + ftype + "'";

            string json = ZLDC.Topo.BLL.Estate.CustomerBLL.p_customerAlertReport_list_table(page, pagesize, condition);
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();
        }

        public static void SelectCustomerOrFollowList()
        {
            int page = _Request.GetInt("page", 0);
            int pagesize = _Request.GetInt("pagesize", 0);
            string StratTime = _Request.GetString("startTime", "");
            string EndTIME = _Request.GetString("EndTime", "");
            string deptid = _Request.GetString("deptname", "");
            string USERID = _Request.GetString("UserName", "");

            string IdList1 = ""; if (_Convert.ToInt(deptid) > 0)
            {

                DataTable dt = ZLDC.DAL.Estate.DeptDAL.getGetAllChildrenDept(deptid);
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if (dt.Rows[i]["id"].ToString() != "")
                    {
                        IdList1 += dt.Rows[i]["id"].ToString() + ",";
                    }
                }
                if (IdList1 != "")
                {
                    IdList1 = IdList1.Substring(0, IdList1.Length - 1);
                }
            }
            string condition = "where dltFlag=0 ";
            string station = _Utility.GetInfoBySession().m_sStation;

            if (ZLDC.Common.BaseUser.UserInfo.GetPopedom("查看全部客源及待看楼盘"))
            {
                if (IdList1 != "")
                    condition += " and fDeptId in(" + IdList1 + ") ";

            }
            else
            {
                if (_Utility.GetWebConfigSetting("SalesManagerStation").Contains(station))
                {
                    string IdList = CacheUtility.Cache_GetAllChildDept(_Utility.GetInfoBySession().m_sDeptID);

                    if (deptid != "")
                    {
                        condition += " and fDeptId in(" + IdList1 + ")   and fDeptId in(" + IdList + ") ";
                    }
                    else
                    {
                        condition += " and fDeptId in(" + IdList + ") ";
                    }
                }
                else
                {

                    condition += " and FUserId ='" + _Utility.GetInfoBySession().m_sUserID + "' ";

                }



            }

            if (StratTime != "" && EndTIME == "")
            {
                condition += " and FDate like '" + StratTime + "%' ";
            }
            if (EndTIME != "" && StratTime == "")
            {
                condition += " and FDate like '" + EndTIME + "%' ";
            }
            if (StratTime != "" && EndTIME != "")
            {
                condition += "  and FDate between '" + StratTime + " 00:00:00" + "' and '" + EndTIME + " 23:59:59" + "' ";
            }

            if (USERID != "")
            {


                string userName = string.Empty; string userNo = string.Empty; int userId = 0; _Utility.GetUserNoAndUserName(USERID.Trim(), out userName, out userNo);
                if (userName == "")
                {
                    condition += " AND FUserId='" + USERID + "' ";

                }
                else
                {
                    userId = ZLDC.Topo.BLL.Estate.UserBLL.GetUserIDByUserNo(userNo);

                    condition += " AND FUserId='" + userId.ToString() + "' ";
                }
            }

            string json = ZLDC.Topo.BLL.Estate.CustomerBLL.p_Customer_Follow_Report_list_table(page, pagesize, condition);
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();

        }

        public static void GetCustTelList()
        {
            string custTel = _Request.GetString("CustTel", "");
            string json = ZLDC.Topo.BLL.Estate.CustomerBLL.GetCustTelList(custTel);

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();
        }

        #region 转介客

        public static void CustomerChangeCheckList()
        {
            int userid = _Convert.ToInt(_Utility.GetInfoBySession().m_sUserID);
            string deptid = _Utility.GetInfoBySession().m_sDeptID;
            string station = _Utility.GetInfoBySession().m_sStation;

            int page = _Request.GetInt("page", 0);
            int pagesize = _Request.GetInt("pagesize", 0);

            string condition = " where status = 1 ";

            if (_Utility.GetWebConfigSetting("SalesManagerStation").Contains(station))
            {
                string deptid_list = CacheUtility.Cache_GetAllChildDept(deptid);
                condition += " and acceptDeptid in(" + deptid_list + ")";
            }
            else if (ZLDC.Common.BaseUser.UserInfo.GetPopedom("查看全部盘源"))
                condition += " ";

            string json = ZLDC.Topo.BLL.Estate.ChangecustomerLogBLL.p_changecustomerlog_list(page, pagesize, condition);

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();
        }

        public static void CustomerChangeCheckOK()
        {
            int id = 0;
            string outmsg = "";
            string[] IDList = _Utility.GetStringBySplit(_Request.GetString("id"), '|');

            if (IDList != null && IDList.Length > 0)
            {
                for (int i = 0; i < IDList.Length; i++)
                {
                    id = _Convert.ToInt(IDList[i], 0);
                    int cid = 0;
                    outmsg = ZLDC.Topo.BLL.Estate.ChangecustomerLogBLL.p_changecustomerlog_check(id, out cid);

                    ZLDC.Topo.BLL.Estate.OperationlogBLL.p_operationlog_insert("t_changeCustomer_log", id, 4, "确认接收转介客源");

                    _Cache.RemoveLike(CacheConst.CACHE_CUSTOMER_FOLLOW_JSON + cid);
                    _Cache.Remove(CacheConst.CACHE_CUSTOMER_DETAIL_JSON + cid.ToString());
                    _Cache.Remove(CacheConst.CACHE_CUSTOMER_DETAIL_INFO + cid.ToString());
                }
            }

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(outmsg);
            HttpContext.Current.Response.End();
        }

        public static void CustomerChangeCheckChange()
        {
            int id = 0;
            string outmsg = "";
            string[] IDList = _Utility.GetStringBySplit(_Request.GetString("id"), '|');

            if (IDList != null && IDList.Length > 0)
            {
                for (int i = 0; i < IDList.Length; i++)
                {
                    id = _Convert.ToInt(IDList[i], 0);
                    int cid = 0;
                    outmsg = ZLDC.Topo.BLL.Estate.ChangecustomerLogBLL.p_changecustomerlog_change(1, id, out cid);

                    ZLDC.Topo.BLL.Estate.OperationlogBLL.p_operationlog_insert("t_changeCustomer_log", id, 4, "登客人的组织架构为空时，接收人可以转公客");

                    _Cache.RemoveLike(CacheConst.CACHE_CUSTOMER_FOLLOW_JSON + cid);
                    _Cache.Remove(CacheConst.CACHE_CUSTOMER_DETAIL_JSON + cid.ToString());
                    _Cache.Remove(CacheConst.CACHE_CUSTOMER_DETAIL_INFO + cid.ToString());
                }
            }

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(outmsg);
            HttpContext.Current.Response.End();
        }

        public static void CustomerChangeCheckDelete()
        {
            int id = 0;
            string outmsg = "";
            string[] IDList = _Utility.GetStringBySplit(_Request.GetString("id"), '|');

            if (IDList != null && IDList.Length > 0)
            {
                for (int i = 0; i < IDList.Length; i++)
                {
                    id = _Convert.ToInt(IDList[i], 0);
                    int cid = 0;
                    outmsg = ZLDC.Topo.BLL.Estate.ChangecustomerLogBLL.p_changecustomerlog_change(2, id, out cid);

                    ZLDC.Topo.BLL.Estate.OperationlogBLL.p_operationlog_insert("t_changeCustomer_log", id, 4, "登客人的组织架构为空时，接收人可以删除该客");

                    _Cache.RemoveLike(CacheConst.CACHE_CUSTOMER_FOLLOW_JSON + cid);
                    _Cache.Remove(CacheConst.CACHE_CUSTOMER_DETAIL_JSON + cid.ToString());
                    _Cache.Remove(CacheConst.CACHE_CUSTOMER_DETAIL_INFO + cid.ToString());
                }
            }

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(outmsg);
            HttpContext.Current.Response.End();
        }

        public static void UpdateCustomerCheckList()
        {
            int id = 0;
            int isself = _Request.GetInt("isself", 0);
            int mark1 = _Request.GetInt("mark1", 0);
            string outmsg = "";
            string[] IDList = _Utility.GetStringBySplit(_Request.GetString("id"), '|');
            int deptid = _Convert.ToInt(_Utility.GetInfoBySession().m_sDeptID, 0);
            string deptname = _Utility.GetInfoBySession().m_sDeptName;
            int userid = _Convert.ToInt(_Utility.GetInfoBySession().m_sUserID, 0);
            string username = _Utility.GetInfoBySession().m_sUserName;

            if (IDList != null && IDList.Length > 0)
            {
                for (int i = 0; i < IDList.Length; i++)
                {
                    id = _Convert.ToInt(IDList[i], 0);
                    outmsg = ZLDC.Topo.BLL.Estate.ChangecustomerLogBLL.UpdateCustomerCheckList(isself, mark1, id);
                    if (outmsg == "审核通过")
                    {
                        ZLDC.Topo.BLL.Estate.CustomerBLL.p_Customerfollow_save(0, id, deptid, deptname, userid, username, "转客审核", outmsg, 0, 0);

                        ZLDC.Topo.Model.Estate.CustomerInfo customer = ZLDC.Topo.BLL.Estate.CustomerBLL.p_customer_detail(id);
                        ZLDC.Topo.BLL.Estate.quantificationBLL.UpdateCustomerChangeQuantification(id, customer.Tradetype, customer.OwnerDeptId, customer.OwnerDept, customer.Ownerid, customer.Owner);
                    }

                    if (id > 0)
                    {
                        _Cache.RemoveLike(CacheConst.CACHE_CUSTOMER_FOLLOW_JSON + id);
                        _Cache.Remove(CacheConst.CACHE_CUSTOMER_DETAIL_JSON + id.ToString());
                        _Cache.Remove(CacheConst.CACHE_CUSTOMER_DETAIL_INFO + id.ToString());
                    }
                }
            }

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(outmsg);
            HttpContext.Current.Response.End();
        }

        public static void CustomerChangeList()
        {
            string json = "";

            int userid = _Convert.ToInt(_Utility.GetInfoBySession().m_sUserID);
            string station = _Utility.GetInfoBySession().m_sStation;
            int page = _Request.GetInt("page", 0);
            int pagesize = _Request.GetInt("pagesize", 0);

            string orderByName = _Request.GetString("orderByName", "modifyDate");
            string orderByType = _Request.GetString("orderByType", "desc");

            string condition = " where dltFlag=0 ";

            if (_Utility.GetWebConfigSetting("SalesManagerStation").Contains(station))
            {
                string deptid_list = CacheUtility.Cache_GetAllChildDept(_Utility.GetInfoBySession().m_sDeptID);
                condition += " and ischange > 0 and (addDeptid in(" + deptid_list + ") or ownerDeptid in(" + deptid_list + "))";
            }
            else if (ZLDC.Common.BaseUser.UserInfo.GetPopedom("查看全部客源"))
                condition += " ";
            else
                condition += " and ischange > 0 and (addUid=" + userid + " or ownerid=" + userid + ")";

            int id = _Request.GetInt("id", 0); if (id > 0)
            {
                condition += " and id=" + id;

                json = ZLDC.Topo.BLL.Estate.CustomerBLL.p_customer_list(page, pagesize, condition, orderByName, orderByType);
                HttpContext.Current.Response.Write(json);
            }

            string customertel = _Request.GetString("customertel", ""); if (!string.IsNullOrEmpty(customertel))
            {
                condition += " and customertel like'%" + customertel + "%'";

                json = ZLDC.Topo.BLL.Estate.CustomerBLL.p_customer_list(page, pagesize, condition, orderByName, orderByType);
                HttpContext.Current.Response.Write(json);
            }

            condition += Utility.GetCustomerCondition();

            json = ZLDC.Topo.BLL.Estate.CustomerBLL.p_customer_list(page, pagesize, condition, orderByName, orderByType);

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();
        }

        public static void CustomerChangeListAction()
        {
            string json = "";

            int userid = _Convert.ToInt(_Utility.GetInfoBySession().m_sUserID);
            string station = _Utility.GetInfoBySession().m_sStation;
            int page = _Request.GetInt("page", 0);
            int pagesize = _Request.GetInt("pagesize", 0);

            string condition = " where dltFlag=0 and ischange=2 ";

            if (_Utility.GetWebConfigSetting("SalesManagerStation").Contains(station))
            {
                string deptid_list = CacheUtility.Cache_GetAllChildDept(_Utility.GetInfoBySession().m_sDeptID);
                condition += " and (addDeptid in(" + deptid_list + ") or ownerDeptid in(" + deptid_list + "))";
            }
            else if (ZLDC.Common.BaseUser.UserInfo.GetPopedom("查看全部客源"))
                condition += " ";
            else
                condition += " and (addUid=" + userid + " or ownerid = " + userid + ")";

            int id = _Request.GetInt("id", 0); if (id > 0)
            {
                condition += " and id=" + id;

                json = ZLDC.Topo.BLL.Estate.CustomerBLL.p_customer_list_action(userid, page, pagesize, condition);
                HttpContext.Current.Response.Write(json);
            }

            string customertel = _Request.GetString("customertel", ""); if (!string.IsNullOrEmpty(customertel))
            {
                condition += " and customertel like'%" + customertel + "%'";

                json = ZLDC.Topo.BLL.Estate.CustomerBLL.p_customer_list_action(userid, page, pagesize, condition);
                HttpContext.Current.Response.Write(json);
            }

            condition += Utility.GetCustomerCondition();

            json = ZLDC.Topo.BLL.Estate.CustomerBLL.p_customer_list_action(userid, page, pagesize, condition);

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();
        }

        public static void CustomerChangeLogList()
        {
            string json = "";

            int id = _Request.GetInt("id", 0);

            int page = _Request.GetInt("page", 0);
            int pagesize = _Request.GetInt("pagesize", 0);

            string condition = " where cid=" + id;

            json = ZLDC.Topo.BLL.Estate.ChangecustomerLogBLL.p_changecustomerlog_list(page, pagesize, condition);

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();
        }

        public static void p_CustomerList()
        {
            int userid = _Request.GetInt("userid", 0);
            string condition = " where dltFlag=0 and (ownerid=" + userid + "  or (addUId=" + userid + " and isChange>0))";
            int cid = _Request.GetInt("cid", 0);
            int page = _Request.GetInt("page", 0);
            int pagesize = _Request.GetInt("pagesize", 0);
            string isself = _Request.GetString("isself", "");
            int status = _Request.GetInt("status", 0);
            string orderByName = _Request.GetString("orderByName", "modifyDate");
            string orderByType = _Request.GetString("orderByType", "desc");

            if (cid > 0)
                condition += " and id=" + cid + " ";
            if (isself != "全部")
                condition += " and isself=" + isself + " ";
            if (status >= 0)
                condition += " and status =" + status + " ";
            string json = ZLDC.Topo.BLL.Estate.CustomerBLL.p_customer_list(page, pagesize, condition, orderByName, orderByType);

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();
        }

        public static void p_CustomerRecycleList()
        {
            int page = _Request.GetInt("page", 0);
            int pagesize = _Request.GetInt("pagesize", 0);
            int CustId = _Request.GetInt("CustId", 0);
            string CustName = _Request.GetString("CustName", "");
            string CustTel = _Request.GetString("CustTel", "");
            string condition = " where dltflag=1 ";
            if (CustId > 0)
                condition += " and id=" + CustId + "";
            if (CustName != "")
                condition += " customer='" + CustName + "'";
            if (CustTel != "")
                condition += " customerTel='" + CustTel + "'";


            string orderByName = _Request.GetString("orderByName", "followUpDate");
            string orderByType = _Request.GetString("orderByType", "desc");

            string json = ZLDC.Topo.BLL.Estate.CustomerBLL.p_customer_list(page, pagesize, condition, orderByName, orderByType);

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();
        }

        public static void DeleteCustomer()
        {
            string outmsg = "";
            string[] IDList = _Utility.GetStringBySplit(_Request.GetString("id"), '|');

            if (IDList != null && IDList.Length > 0)
            {
                for (int i = 0; i < IDList.Length; i++)
                {
                    int id = _Convert.ToInt(IDList[i], 0);
                    outmsg = ZLDC.Topo.BLL.Estate.CustomerBLL.DeleteCustomer(id);

                    if (id > 0)
                    {
                        _Cache.RemoveLike(CacheConst.CACHE_CUSTOMER_FOLLOW_JSON + id);
                        _Cache.Remove(CacheConst.CACHE_CUSTOMER_DETAIL_JSON + id.ToString());
                        _Cache.Remove(CacheConst.CACHE_CUSTOMER_DETAIL_INFO + id.ToString());
                    }
                }
            }

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(outmsg);
            HttpContext.Current.Response.End();
        }

        public static void DeleteCustomerAlert()
        {
            string outmsg = "";
            int id = _Request.GetInt("id");
            outmsg = ZLDC.Topo.BLL.Estate.CustomerBLL.DeleteCustomerAlert(id);
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(outmsg);
            HttpContext.Current.Response.End();

        }

        public static void DeleteWeekDaysCustomer()
        {
            string outmsg = "";

            outmsg = ZLDC.Topo.BLL.Estate.CustomerBLL.DeleteWeekDaysCustomer();

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(outmsg);
            HttpContext.Current.Response.End();
        }

        public static void p_Customerfollow_delete()
        {
            string[] IDList = _Utility.GetStringBySplit(_Request.GetString("id"), '|');
            int id = 0;
            string outmsg = "";
            for (int i = 0; i < IDList.Length; i++)
            {
                id = Convert.ToInt32(IDList[i]);
                outmsg = ZLDC.Topo.BLL.Estate.CustomerBLL.p_Customerfollow_delete(id);

                if (id > 0)
                    _Cache.RemoveLike(CacheConst.CACHE_CUSTOMER_FOLLOW_JSON + id);
            }
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(outmsg);
            HttpContext.Current.Response.End();
        }

        public static void UpdateDltFlag()
        {
            string outmsg = "";
            string[] IDList = _Utility.GetStringBySplit(_Request.GetString("id"), '|');

            if (IDList != null && IDList.Length > 0)
            {
                for (int i = 0; i < IDList.Length; i++)
                {
                    outmsg = ZLDC.Topo.BLL.Estate.CustomerBLL.UpdateDltFlag(_Convert.ToInt(IDList[i], 0));
                }
            }

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(outmsg);
            HttpContext.Current.Response.End();
        }

        public static void UpdateStatus()
        {
            string id = "";
            int deptid_from = _Request.GetInt("deptid_from", 0); string deptname_from = _Request.GetString("deptname_from", "");
            int userid_from = _Request.GetInt("userid_from", 0);
            string username_from = _Request.GetString("username_from", "");

            string userid_to = _Request.GetString("userid_to", ""); int deptid_to = _Request.GetInt("deptid_to", 0);
            string deptname_to = _Request.GetString("deptname_to", "");
            string username_to = _Request.GetString("username_to", "");
            string flag = _Request.GetString("flag", "");

            ZLDC.Topo.Model.Estate.UserInfo user = ZLDC.Topo.BLL.Estate.UserBLL.GetUserInfoByUserNo(userid_to); if (user == null)
            {
                HttpContext.Current.Response.Clear();
                HttpContext.Current.Response.Write("楼盘系统中没有此用户(" + username_to + ")！");
                HttpContext.Current.Response.End();
            }
            int uid_to = user.Id;
            int rows = 0;
            string CostomerId = _Request.GetString("id", "");
            string[] IdList = null;
            if (CostomerId != "")
            {
                IdList = _Utility.GetStringBySplit(CostomerId, '|');
                if (IdList.ToString() != "" && IdList != null)
                {
                    for (int i = 0; i < IdList.Length; i++)
                    {
                        string cachekey = CacheConst.CACHE_CUSTOMER_DETAIL_JSON + IdList[i].ToString(); _Cache.Remove(cachekey);
                        id += IdList[i].ToString() + ",";
                    }
                    if (id.Length > 0)
                    {
                        id = id.Substring(0, id.Length - 1);
                    }
                }
            }

            if (username_from != "" && userid_from > 0 && deptid_from > 0 && deptname_from != "")
            {
                deptname_to = deptname_to.Substring(1, deptname_to.Length - 1);
                rows = ZLDC.Topo.BLL.Estate.CustomerBLL.UpdateStatus(id, deptid_from, deptname_from, userid_from, username_from, flag, uid_to, deptid_to, deptname_to, username_to);
            }
            string outmsg = "";
            if (rows > 0)
            {
                if (CostomerId != "")
                {
                    for (int j = 0; j < IdList.Length; j++)
                    {
                        int Customerid = _Convert.ToInt(IdList[j]); ZLDC.Topo.BLL.Estate.CustomerBLL.p_Customerfollow_save(0, Customerid, _Convert.ToInt(_Utility.GetInfoBySession().m_sDeptID.ToString()), _Utility.GetInfoBySession().m_sDeptName, _Convert.ToInt(_Utility.GetInfoBySession().m_sUserID.ToString()), _Utility.GetInfoBySession().m_sUserName, "业务员转客", "经理转客：[转出人:" + username_from + ",转入人:" + username_to + "]", 0, 0);
                        if (Customerid > 0)
                            _Cache.RemoveLike(CacheConst.CACHE_CUSTOMER_FOLLOW_JSON + Customerid);
                    }
                }


                outmsg = "操作成功！";

            }
            else
            {
                outmsg = "操作失败，请联系管理员！";
            }
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(outmsg);
            HttpContext.Current.Response.End();
        }

        #endregion

        #region 客源匹配

        public static void CustomerMatch()
        {
            int userid = _Convert.ToInt(_Utility.GetInfoBySession().m_sUserID);
            int page = _Request.GetInt("page", 0);
            int pagesize = _Request.GetInt("pagesize", 0);

            string dname = _Request.GetString("dname", ""); string area = _Request.GetString("area", ""); string usage = _Request.GetString("usage", ""); string buildname = _Request.GetString("buildname", ""); string tradetype = _Request.GetString("tradetype", ""); int minPrice = _Request.GetInt("minPrice", 0); int maxPrice = _Request.GetInt("maxPrice", 0); int minAcreage = _Request.GetInt("minAcreage", 0); int maxAcreage = _Request.GetInt("maxAcreage", 0); int room = _Request.GetInt("room", 0); string direct = _Request.GetString("direct", "");
            string condition = " where dltFlag=0 and isvalid < 2 ";
            if (area != "" && !area.Contains("全部"))
                condition += " and CHARINDEX('" + area + "', area) > 0";

            if (usage != "")
                condition += " and usage = '" + usage + "'";

            if (room > 0)
                condition += " and room = " + room;

            if (tradetype != "" && tradetype != "租售")
                condition += " and tradetype = '" + tradetype + "'";

            if (direct != "")
                condition += " and direct = '" + direct + "'";

            if (minPrice >= 0 && maxPrice > 0)
                condition += " and minPrice >=" + minPrice + " and maxPrice < " + maxPrice;

            if (minAcreage >= 0 && maxAcreage > 0)
                condition += " and minAcreage >=" + minAcreage + " and maxAcreage < " + maxAcreage;

            if (buildname != "")
                condition += " and CHARINDEX('" + buildname + "', estates) > 0";

            string json = ZLDC.Topo.BLL.Estate.CustomerBLL.p_customer_list(page, pagesize, condition);

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();
        }

        #endregion

        #region 成交客管理

        public static void CustomerTranctionEdit()
        {
            string outmsg = "";
            int typeid = _Request.GetInt("typeid", 1); string[] IDList = _Utility.GetStringBySplit(_Request.GetString("id"), '|');

            if (IDList != null && IDList.Length > 0)
            {
                for (int i = 0; i < IDList.Length; i++)
                {
                    outmsg = ZLDC.Topo.BLL.Estate.CustomerBLL.OpenStatus(_Convert.ToInt(IDList[i], 0), typeid);
                }
            }

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(outmsg);
            HttpContext.Current.Response.End();
        }


        #endregion

        public static void ShowOtherCustomer()
        {
            int id = _Request.GetInt("id", 0);

            string json = ZLDC.Topo.BLL.Estate.CustomerBLL.ShowOtherCustomer(id);

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();
        }


        public static void p_showFloorPaper_save()
        {
            string typeId = _Request.GetString("typeId", "0");
            string userId = _Request.GetString("userId", "0");

            string userName = _Request.GetString("userName", "");

            string lookNum = _Request.GetString("inputNum1", "");


            int sNum = _Request.GetInt("sNum", 0);

            int eNum = _Request.GetInt("eNum", 0);


            int s_UserId = _Convert.ToInt(_Utility.GetInfoBySession().m_sUserID);

            string s_UserName = _Utility.GetInfoBySession().m_sUserName;

            string outmsg = "";
            if (typeId == "1")
            {
                outmsg = ZLDC.Topo.BLL.Estate.ShowFloorPaperBLL.p_showFloorPaper_save(0, lookNum, s_UserId, s_UserId, s_UserName, _Convert.ToInt(userId), userName, 0);
            }
            else if (typeId == "2")
            {

                if (sNum <= eNum)
                {
                    System.Text.StringBuilder strButer = new System.Text.StringBuilder();

                    strButer.Append("begin tran;");

                    int rowCount = 0;

                    for (int i = sNum; i <= eNum; i++)
                    {

                        if (ZLDC.Topo.BLL.Estate.ShowFloorPaperBLL.IsExistsPaperNo(i) > 0)
                        {
                            rowCount++;
                            outmsg += i + ",";
                        }

                        strButer.Append(" insert into t_showFloorPaper(paperNo,addUserId,oprUserId,oprUserName,ownerUserId,ownerUserName,isUse) values('" + i.ToString() + "'," + s_UserId + "," + s_UserId + ",'" + s_UserName + "'," + userId + ",'" + userName + "',0) ");

                    }

                    strButer.Append("if " + rowCount + ">0 begin rollback end else begin commit end;");


                    if (strButer.ToString() != string.Empty)
                    {

                        using (_Database db = new _Database("estate"))
                        {
                            db.ExecuteSql(strButer.ToString());

                            db.close();
                        }

                    }
                    if (rowCount == 0)
                        outmsg = "分配成功！";
                    else
                        outmsg += "看楼纸已经存在,请重新分配！";


                }

            }

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(outmsg);
            HttpContext.Current.Response.End();
        }

        public static void ShowFloorPaper_list()
        {
            int page = _Request.GetInt("page", 0);
            int pagesize = _Request.GetInt("pagesize", 0);
            int userId = _Request.GetInt("userId", 0);
            int paparNo = _Request.GetInt("paparNo", 0);
            string condition = " where owneruserid=" + userId + "";

            if (paparNo > 0)
            {
                condition += " and paperNo='" + paparNo + "' ";
            }

            string json = ZLDC.Topo.BLL.Estate.ShowFloorPaperBLL.p_showFloorPaper_list_table(page, pagesize, condition);

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();
        }
        public static void GetUserList()
        {
            int page = _Request.GetInt("page", 0);

            int pagesize = _Request.GetInt("pagesize", 0);

            string user_name = _Request.GetString("userName", "");

            string userName;

            string userNo;

            _Utility.GetUserId(user_name, out userName, out userNo);
            string condition = " where status<>'离职' and dltflg = 0";
            if (userName == "")
            {
                condition += " and t_id=" + _Utility.GetInfoBySession().m_sDeptID + "";
            }
            else
            {
                condition += " and user_name='" + userName + "'";
            }
            string json = ZLDC.Topo.BLL.Estate.UserBLL.p_v_usr_link_list_table(page, pagesize, condition);

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();
        }

        public static void ShowFloorPaper_delete()
        {

            string IdList = _Request.GetString("IdList", "0,");


            IdList = IdList.Replace('|', ',');

            IdList = IdList.Substring(0, IdList.Length - 1);

            string json = ZLDC.Topo.BLL.Estate.ShowFloorPaperBLL.p_showFloorPaper_delete(IdList);

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();


        }


    }
}
